package nc.ui.bd.pub.editor.card.afteredit.body;

import nc.bs.framework.common.NCLocator;
import nc.itf.bd.med_marketauth_holder_148.IMarketAuthMaintainService;
import nc.ui.medpub.editor.card.listener.ICardBodyAfterEditEventListener;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillItem;
import nc.ui.pubapp.uif2app.event.card.CardBodyAfterEditEvent;
import nc.vo.bd.med_marketauth_holder_148.MedMarketAuthHolder_148;
import nc.vo.pub.BusinessException;
import nc.vo.pub.ISuperVO;

public class MarketAuth
  implements ICardBodyAfterEditEventListener
{
  public void afterEdit(CardBodyAfterEditEvent e)
  {
    BillCardPanel card = e.getBillCardPanel();
    BillItem billItem = card.getBodyItem(e.getKey());

    IMarketAuthMaintainService marketService = 
      (IMarketAuthMaintainService)NCLocator.getInstance().lookup(IMarketAuthMaintainService.class);
    String pk_licensor = (String)card.getBodyValueAt(e.getRow(), e.getKey());
    if ((pk_licensor == null) || ("".equals(pk_licensor.trim()))) {
      card.setBodyValueAt(null, e.getRow(), "vlicensorname_148");
      card.setBodyValueAt(null, e.getRow(), "vlicensoraddr_148");
      return;
    }
    try {
      ISuperVO[] vos = marketService.selectByWhereSql("pk_licensor='" + 
        pk_licensor + "'", MedMarketAuthHolder_148.class);
      if ((vos == null) || (vos.length == 0)) {
        card.setBodyValueAt(null, e.getRow(), "vlicensorname_148");
        return;
      }
      card.setBodyValueAt(vos[0].getAttributeValue("name"), 
        e.getRow(), "vlicensorname_148");
      card.setBodyValueAt(vos[0].getAttributeValue("vaddress"), 
        e.getRow(), "vlicensoraddr_148");
    }
    catch (BusinessException e1) {
      e1.printStackTrace();
    }
  }
}